@extends('admin.layout')

@section('content')

<body>
<form method="post" action="">
    <div class="panel admin-panel">
        <div class="panel-head"><strong class="icon-reorder"> 留言管理</strong></div>
        
        <table class="table table-hover text-center">
            <tr>
                <th width="5%">ID</th>
                <th width="10%">用户名</th>       
                <th width="20%">文章标题</th>
                <th width="25%">评论内容</th>
                <th width="20%">评论时间</th>
                <th width="10%">操作</th>       
            </tr>     
            
            @foreach($comments as $comment)
            <tr>
                <td>{{ $loop->iteration }}</td>
                <td>{{ $comment->username }}</td>
                <td>{{ $comment->title }}</td>
                <td>{{ $comment->content }}</td>  
                <td>{{ $comment->created_at }}</td>         
                <td><div class="button-group"> <a class="button border-red" href="javascript:void(0)" onclick="delComment({{ $comment->id }})"><span class="icon-trash-o"></span> 删除</a> </div></td>
            </tr>
            @endforeach
            <tr>
                <td colspan="8">{{ $comments->links() }}</td>
            </tr>
        </table>
    </div>
</form>
<script type="text/javascript">
    function delComment(id) {

        var _token = "{{ csrf_token() }}";

        layer.confirm("您确定要删除吗？",function() {
            $.ajax({
                type:'delete',
                url:'/admin/comment/delete/'+id,
                datatype:'json',
                data:{_token:_token},
                success:function(res) {
                    if ( res.status == 'success' ) {
                        location.href="{{ url('admin/comment') }}";
                    } else {
                        layer.msg(res.msg , {icon:2});
                    }
                }
            })
        })
    }
</script>
</body>

@endsection